package threads;

import java.util.concurrent.Semaphore;

public class PrintAZ026Test_Semaphore {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(1, true);
        Thread t1 = new Thread(() -> {
            for (int i = 'A'; i <= 'Z'; i++) {
                try {
                    semaphore.acquire();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println((char) i);
                semaphore.release();

            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 1; i <= 26; i++) {
                try {
                    semaphore.acquire();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
                semaphore.release();
            }
        });
        t1.start();
        t2.start();
    }
}
